package com.example.everying.task;/*
 * 项目名称: everything
 * 文件名: ClearPointTask
 * 作者: 张泽阳
 * 日期: 2025/8/1
 * 描述:
 */


import com.example.everying.service.user.PointsAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class ClearPointTask {

    @Autowired
    private PointsAccountService pointsAccountService;

    // 每年1月1日0点执行
    @Scheduled(cron = "0 3 0 1 1 *")
    public void clearPoint() {

        log.info("开始执行积分清零任务");
        int i = pointsAccountService.clearPoints(LocalDateTime.now());
        if (i <= 0){
            log.info("无用户积分可清零");
        }
        log.info("已清零{}个用户积分", i);
    }
}
